﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace PotatoSoft.CustomControl
{
    /// <summary>
    /// Interaction logic for OutputControl.xaml
    /// </summary>
    public partial class OutputControl : UserControl
    {
        #region "Properties"

        /// <summary>
        /// zbior wiadomosci
        /// </summary>
        private List<string> Messages { get; set; }

        #endregion

        #region "Constructors"

        public OutputControl()
        {
            InitializeComponent();
            Messages = new List<string>();
        }

        #endregion

        #region "Methods"

        /// <summary>
        /// dodaj wiadomosc do listy
        /// </summary>
        /// <param name="message">wiadomosc do dodania</param>
        public void AddMessage(string message)
        {
            Messages.Add(message);
            AddTextBox(message);
        }
        /// <summary>
        /// update zawartosci kontrolki
        /// </summary>
        public void Update()
        {
            contener.Children.Clear();
            int count = 0;
            foreach (var item in Messages)
            {
                AddTextBox(Messages[count], "message-" + count.ToString());
                count++;
            }
        }
        /// <summary>
        /// czyszczenie kontrolki i listy wiadomosci
        /// </summary>
        public void Clear()
        {
            Messages.Clear();
            contener.Children.Clear();
        }
        /// <summary>
        /// dodaje textbox do glownego kontenera
        /// </summary>
        /// <param name="text">text wiadomosci</param>
        /// <param name="name">nazwa textboxa, parametr opcjonalny</param>
        private void AddTextBox(string text, string name = "")
        {
            var textblock = new TextBlock();
            textblock.Name = name;
            textblock.Text = text;
            contener.Children.Add(textblock);
        }

        #endregion
    }
}
